﻿using System;

namespace MultiDelegates
{


    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("计算机开始做一项艰难的工作.......");

            ProcessReporter p = WriteProcessToConsole;
            p += WriteProcessToFile;

            Util.HardWork(p);
            Console.WriteLine("恭喜工作完成了");
        }


        static void WriteProcessToConsole(int percentComplete)
        =>Console.WriteLine(percentComplete);
        

        static void WriteProcessToFile(int percentComplete)
        => System.IO.File.AppendAllText("report.txt", percentComplete.ToString()+"\r\n");
    }


    public delegate void ProcessReporter(int percentComplete);

    public class Util
    {
        public static void HardWork(ProcessReporter processReporter)
        {
            for (int i = 0; i < 10; i++)
            {
                processReporter(i * 10);
                System.Threading.Thread.Sleep(500);//模拟总共5秒钟的时间

            }
        }
    }
}
